package com.knoya.chejian.pda.module.outsourcing

import android.content.Context
import android.util.Log
import com.knoya.chejian.pda.minterface.OnUserDataInterface
import com.knoya.chejian.pda.util.Myutil

class OutsourcingP : OutsourcingContract.OutsourcingKP {
    var context: Context
    var mlist : MutableList<String>
    var PV : OutsourcingContract.OutsourcingView?=null
    var MP : OutsourcingContract.OutsourcingMP = OutsourcingM()
    var code = 1

    constructor(mlist: MutableList<String> , PV: OutsourcingContract.OutsourcingView, context: Context) {
        this.mlist = mlist
        this.PV = PV
        this.context=context
    }

    override fun putOutsourcing() {
        var OutsourcingBeanList : MutableList<OutsourcingBean> = ArrayList<OutsourcingBean>()
        for (i in 0 until mlist.size){
            var bean = OutsourcingBean()
            bean.scrn_string = mlist[i]

            OutsourcingBeanList.add(bean)
        }
        if(mlist.size == 0){
            Myutil.MyTost("没有扫描，不能上传")
            PV?.putOutsourcingNo()
            return;
        }
        MP.putOutsourcing(context,OutsourcingBeanList,object : OnUserDataInterface {
            override fun onUserData(data: String?) {
                Log.d("TAAAG",data)
                PV?.putOutsourcingOk()
            }

            override fun onNot(throwable: String?) {
                PV?.putOutsourcingNo()
            }

        })
    }

    override fun deleteOutsourcing() {
        var OutsourcingBeanList : MutableList<OutsourcingBean> = ArrayList<OutsourcingBean>()
        for (i in 0 until mlist.size){
            var bean = OutsourcingBean()
            bean.scrn_string = mlist[i]

            OutsourcingBeanList.add(bean)
        }
        if(mlist.size == 0){
            Myutil.MyTost("没有扫描，不能清除")
            PV?.putOutsourcingNo()
            return;
        }
        MP.deleteOutsourcing(context,OutsourcingBeanList,object : OnUserDataInterface {
            override fun onUserData(data: String?) {
                Log.d("TAAAG",data)
                PV?.deleteOutsourcingOk()
            }

            override fun onNot(throwable: String?) {
                PV?.deleteOutsourcingNo()
            }

        })
    }
}